here_long <- -122.3095
here_lat <- 47.6560
seattle = get_map(location = c(here_long, here_lat), zoom = 13, maptype = 'roadmap')
Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=47.656,-122.3095&zoom=13&size=640x640&scale=2&maptype=roadmap&language=en-EN&sensor=false
spd.911 <- spd.911 %>%
rowwise() %>%
mutate(dist=distVincentyEllipsoid(c(Longitude, Latitude), c(here_long, here_lat)))
nrow(spd.911)
[1] 257011
descriptions <- c("STRONG ARM ROBBERY", "PERSON WITH A WEAPON (NOT GUN)", "HAZARDS", "HARASSMENT, THREATS", "FIGHT DISTURBANCE", "CRISIS COMPLAINT - GENERAL", "ARMED ROBBERY")
# Removes Specifically Harassment by Telephone and Writing, as well as other non-scary crimes
data.ped <- spd.911 %>% filter(str_detect(Event.Clearance.Description, paste(descriptions, collapse="|"))) %>% filter(!str_detect(Event.Clearance.Description, "HARASSMENT, THREATS - BY TELEPHONE, WRITING")) %>% filter(!str_detect(Event.Clearance.Description, "HARBOR DEBRIS, NAVIGATIONAL HAZARDS"))
nrow(data.ped)
[1] 15606
data.here <- data.ped %>% filter(dist < 2600)
data.w.at.scene <- filter(data.here, !is.na(at_scene_time_date))
data <- data.w.at.scene
nrow(data)
[1] 722
# View(data)
write.csv(data, '2016-2017-Clean.csv')
data <- read.csv('2016-2017-Clean.csv', header = TRUE)
# View(data)
data <- filter(data, !str_detect(Event.Clearance.Description, "HARBOR - DEBRIS, NAVIGATIONAL HAZARDS"))
nrow(data)
[1] 710
ggmap(seattle) +
geom_point(data = data, aes(x = Longitude, y = Latitude), colour = "red", alpha = 0.75)

#coord_map()
cor(1:12, data.frame(by.month)$Freq)
[1] 0.4616517
freq_by_desc <- table(droplevels(data$Event.Clearance.Description))
# View(freq_by_desc)
ggplot(as.data.frame(freq_by_desc),
aes(x = Var1, y = Freq)) +
geom_bar(stat = 'identity') +# create bar plot
coord_flip()

#Traffic related calls, suspicious circumstances, and disturbances are the the most significant threats to pedestrations
ggmap(seattle) +
geom_point(data = data, aes(x = Longitude, y = Latitude, group = Event.Clearance.Description, color = Event.Clearance.Description), alpha = 0.5, size = 10) +
facet_wrap(~ Event.Clearance.Description) +
theme(axis.ticks = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
strip.text = element_text(size=50),
legend.position = "none"
)
